Skip to content

fix: fallback dock theme to system settings on wayland#1605

Merged
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
May 27, 2026
Merged

fix: fallback dock theme to system settings on wayland#1605
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Copy Markdown
Contributor

@18202781743 18202781743 commented May 21, 2026

  1. Disable WallpaperColorManager initialization in WaylandDockHelper
    constructor
  2. Extract wallpaper color management to a separate
    initWallpaperColorManager() method
  3. Connect dock theme changes to DGuiApplicationHelper themeTypeChanged
    signal on Wayland
  4. This ensures dock follows system theme when wallpaper color is
    unavailable

Log: Dock theme on Wayland now falls back to system color settings

Influence:

  1. Test dock color theme toggling between light and dark on Wayland
  2. Verify dock theme syncs with system settings after change
  3. Ensure no regression in dock color behavior on X11
  4. Check that wallpaper color feature is cleanly disabled without errors
  5. Verify dock screen changes don't trigger wallpaper color manager
    calls

fix: wayland下dock暗亮色回退到系统设置

  1. 禁用WaylandDockHelper构造函数中的WallpaperColorManager初始化
  2. 将壁纸颜色管理提取到独立的initWallpaperColorManager()方法中
  3. 在Wayland上连接dock主题变化到DGuiApplicationHelper的themeTypeChanged
    信号
  4. 确保壁纸颜色不可用时dock遵循系统主题

Log: Wayland下Dock主题现在回退到系统颜色设置

Influence:

  1. 在Wayland上测试dock颜色主题在亮色和暗色间切换
  2. 验证dock主题在系统设置更改后同步
  3. 确保X11上dock颜色行为无回归
  4. 检查壁纸颜色功能被干净禁用,无错误产生
  5. 验证dock屏幕变化不会触发壁纸颜色管理器调用

PMS: BUG-344841

Summary by Sourcery

Make the Wayland dock fall back to system theme settings when wallpaper-based colors are unavailable.

Bug Fixes:

  • Ensure the dock color theme on Wayland tracks system light/dark theme changes when wallpaper color data is not available.

Enhancements:

  • Isolate wallpaper color management into an initWallpaperColorManager() helper for future re-enablement.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 21, 2026

Reviewer's Guide

Refactors Wayland dock wallpaper color handling by disabling WallpaperColorManager initialization on Wayland, extracting it into a dedicated initializer, and wiring the dock’s color theme to DGuiApplicationHelper’s themeTypeChanged signal so that on Wayland the dock falls back to system theme colors when wallpaper-based colors are unavailable.

Sequence diagram for dock theme fallback to system settings on Wayland

sequenceDiagram
    participant DGuiApplicationHelper
    participant DockPanel
    participant WaylandDockHelper
    participant WallpaperColorManager

    Note over DockPanel,WaylandDockHelper: Wayland platform

    alt [wallpaper color available]
        DockPanel->>WaylandDockHelper: initWallpaperColorManager()
        WaylandDockHelper->>WallpaperColorManager: watchScreen(dockScreenName())
        WallpaperColorManager-->>DockPanel: activeChanged
        DockPanel->>DockPanel: setColorTheme(ColorTheme_from_wallpaper)
    else [wallpaper color unavailable]
        DGuiApplicationHelper-->>DockPanel: themeTypeChanged
        DockPanel->>DockPanel: setColorTheme(ColorTheme_from_themeType)
    end
Loading

File-Level Changes

Change Details Files
Disable WallpaperColorManager usage in WaylandDockHelper and move its setup into a dedicated initializer for future reuse.
  • Remove immediate construction of WallpaperColorManager from WaylandDockHelper constructor.
  • Remove connections from DockPanel and wallpaper color signals that were previously established in the WaylandDockHelper constructor.
  • Introduce initWallpaperColorManager() that encapsulates WallpaperColorManager creation, signal wiring, and initial watchScreen setup without invoking it yet.
panels/dock/waylanddockhelper.cpp
panels/dock/waylanddockhelper.h
Make Wayland dock theme follow DGuiApplicationHelper’s themeTypeChanged signal as a fallback when wallpaper colors are not available.
  • Initialize dock theme from DGuiApplicationHelper::themeType regardless of platform.
  • On Wayland platform, create WaylandDockHelper but additionally connect DGuiApplicationHelper::themeTypeChanged to DockPanel::setColorTheme for fallback theme synchronization.
  • Retain existing X11 (xcb) themeTypeChanged connection for regression safety.
panels/dock/dockpanel.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The new initWallpaperColorManager() helper is currently unused; consider either wiring it behind a clear feature flag or removing it for now to avoid dead code and keep the Wayland path easier to reason about.
  • In DockPanel::init() on Wayland, the themeTypeChanged connection is created unconditionally; if init() can be called more than once, consider using Qt::UniqueConnection or moving this connection to the constructor to avoid accumulating duplicate connections.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `initWallpaperColorManager()` helper is currently unused; consider either wiring it behind a clear feature flag or removing it for now to avoid dead code and keep the Wayland path easier to reason about.
- In `DockPanel::init()` on Wayland, the `themeTypeChanged` connection is created unconditionally; if `init()` can be called more than once, consider using `Qt::UniqueConnection` or moving this connection to the constructor to avoid accumulating duplicate connections.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

1. Disable WallpaperColorManager initialization in WaylandDockHelper
constructor
2. Extract wallpaper color management to a separate
initWallpaperColorManager() method
3. Connect dock theme changes to DGuiApplicationHelper themeTypeChanged
signal on Wayland
4. This ensures dock follows system theme when wallpaper color is
unavailable

Log: Dock theme on Wayland now falls back to system color settings

Influence:
1. Test dock color theme toggling between light and dark on Wayland
2. Verify dock theme syncs with system settings after change
3. Ensure no regression in dock color behavior on X11
4. Check that wallpaper color feature is cleanly disabled without errors
5. Verify dock screen changes don't trigger wallpaper color manager
calls

fix: wayland下dock暗亮色回退到系统设置

1. 禁用WaylandDockHelper构造函数中的WallpaperColorManager初始化
2. 将壁纸颜色管理提取到独立的initWallpaperColorManager()方法中
3. 在Wayland上连接dock主题变化到DGuiApplicationHelper的themeTypeChanged
信号
4. 确保壁纸颜色不可用时dock遵循系统主题

Log: Wayland下Dock主题现在回退到系统颜色设置

Influence:
1. 在Wayland上测试dock颜色主题在亮色和暗色间切换
2. 验证dock主题在系统设置更改后同步
3. 确保X11上dock颜色行为无回归
4. 检查壁纸颜色功能被干净禁用,无错误产生
5. 验证dock屏幕变化不会触发壁纸颜色管理器调用

PMS: BUG-344841
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX,你的智能编程助手。我已经仔细审查了你提供的Git Diff代码。

这次代码变更的主要目的是:将Wayland环境下的壁纸颜色管理器(WallpaperColorManager)的初始化延迟,并在当前暂时回退到使用DGuiApplicationHelper的主题颜色信号来更新Dock颜色,同时预留了未来重新启用壁纸取色功能的接口。

整体思路上没有严重的逻辑错误,但在代码质量、性能和安全性方面,有一些值得注意和改进的地方。以下是详细的审查意见:

1. 语法与逻辑

  • 重复的信号槽连接逻辑
    dockpanel.cpp 中,Wayland 和 XCB 两个分支下,连接 DGuiApplicationHelper::themeTypeChanged 的 Lambda 表达式逻辑完全一致:

    this, [this]() {
        setColorTheme(static_cast<ColorTheme>(Dtk::Gui::DGuiApplicationHelper::instance()->themeType()));
    }

    改进意见:既然 Wayland 目前作为 Fallback 也采用了和 XCB 相同的逻辑,可以将这段连接代码提取到 if-else 外部,减少代码冗余。

  • initWallpaperColorManager 未被调用
    waylanddockhelper.h 中声明了 void initWallpaperColorManager();,在 .cpp 中也实现了它,但在构造函数中只是将原本的初始化和信号连接代码移除了,并没有任何地方调用 initWallpaperColorManager()
    改进意见:如果当前版本确实不需要启用该功能,建议在注释中明确说明,或者在代码中预留调用(例如注释掉 // initWallpaperColorManager();),否则这段代码变成了“死代码”,容易在后续迭代中被遗忘。

2. 代码质量

  • TODO 注释的清晰度
    新增的注释 // TODO: remove this when initWallpaperColorManager is re-enabled 写得很好,指明了这段代码的临时性质。但建议进一步补充原因,例如是因为 Wayland 取色 API 不稳定、性能问题,还是特定Bug导致。这能帮助未来的维护者更快做出决策。
  • 多余的空行
    waylanddockhelper.cpp 第 51 行附近,删除代码后留下了连续的空行,建议清理以保持代码整洁。

3. 代码性能

  • 信号槽触发的频率与重复计算
    DGuiApplicationHelper::themeTypeChanged 在主题切换时可能会高频触发。每次触发都会调用 static_cast<ColorTheme>(...)setColorTheme(...)
    改进意见:建议在 setColorTheme 内部(或者 Lambda 捕获时)增加状态判断,如果计算出的新主题与当前主题 m_theme 一致,则直接 return,避免不必要的 UI 刷新和信号级联触发。

4. 代码安全

  • Lambda 捕获 this 的生命周期风险
    dockpanel.cpp 中,Lambda 捕获了 this(即 DockPanel 实例),并连接到了全局单例 DGuiApplicationHelper::instance() 的信号上。
    由于 DockPanel 的生命周期通常比全局单例短,如果 DockPanel 在销毁时没有确保断开这个连接,就会导致悬垂指针,进而引发崩溃。
    改进意见:虽然 Qt 的 QObject 机制在对象销毁时会自动断开与其相关的所有信号槽连接(前提是接收者也是 QObject 且在同一个线程),但为了代码的健壮性和明确性,建议在 DockPanel 的析构函数中显式调用 disconnect,或者使用 Qt5.15+ 提供的上下文对象连接方式(确保当 this 销毁时,连接自动断开)。

💡 综合改进建议代码示例

基于以上分析,我为你提供一份优化后的代码参考:

panels/dock/dockpanel.cpp

 bool DockPanel::init()
 {
     m_theme = static_cast<ColorTheme>(Dtk::Gui::DGuiApplicationHelper::instance()->themeType());
     auto platformName = QGuiApplication::platformName();
     if (QStringLiteral("wayland") == platformName) {
         m_helper = new WaylandDockHelper(this);
-        // Fallback to DGuiApplicationHelper for theme color when wayland wallpaper color is not available.
-        // TODO: remove this when initWallpaperColorManager is re-enabled
-        QObject::connect(Dtk::Gui::DGuiApplicationHelper::instance(), &Dtk::Gui::DGuiApplicationHelper::themeTypeChanged,
-                         this, [this]() {
-            setColorTheme(static_cast<ColorTheme>(Dtk::Gui::DGuiApplicationHelper::instance()->themeType()));
-        });
     } else if (QStringLiteral("xcb") == platformName) {
-        QObject::connect(Dtk::Gui::DGuiApplicationHelper::instance(), &Dtk::Gui::DGuiApplicationHelper::themeTypeChanged,
-                            this, [this](){
-            setColorTheme(static_cast<ColorTheme>(Dtk::Gui::DGuiApplicationHelper::instance()->themeType()));
-        });
+        // XCB 分支无需额外处理,统一在外部处理主题变更
     }
+
+    // Fallback to DGuiApplicationHelper for theme color when wayland wallpaper color is not available.
+    // TODO: remove this when initWallpaperColorManager is re-enabled (due to Wayland color extraction API instability)
+    QObject::connect(Dtk::Gui::DGuiApplicationHelper::instance(), &Dtk::Gui::DGuiApplicationHelper::themeTypeChanged,
+                     this, [this]() {
+        ColorTheme newTheme = static_cast<ColorTheme>(Dtk::Gui::DGuiApplicationHelper::instance()->themeType());
+        if (m_theme != newTheme) { // 性能优化:避免无意义的重复赋值和UI刷新
+            setColorTheme(newTheme);
+        }
+    });
+
     // ... 其他代码 ...
 }

panels/dock/waylanddockhelper.cpp

 WaylandDockHelper::WaylandDockHelper(DockPanel *panel)
     : m_isCurrentActiveWindowFullscreened(false)
     , m_panel(panel)
 {
     m_ddeShellManager.reset(new TreeLandDDEShellManager());
     DS_NAMESPACE::DAppletBridge bridge("org.deepin.ds.dock.taskmanager");
     if (auto applet = bridge.applet()) {
         // ...
     }
 
-    // 此处清理了多余的空行
     connect(m_panel, &DockPanel::positionChanged, this, &WaylandDockHelper::updateOverlapCheckerPos);
     connect(m_panel, &DockPanel::dockSizeChanged, this, &WaylandDockHelper::updateOverlapCheckerPos);
     // ...
     
+    // TODO: 目前 Wayland 壁纸取色功能暂未稳定,暂不初始化 WallpaperColorManager
+    // initWallpaperColorManager(); 
 }

通过以上改进,代码的冗余度降低,性能更好,且对生命周期的管理更加安全明确。如果有任何其他问题,欢迎随时提问!

@18202781743 18202781743 merged commit ae3a27b into linuxdeepin:master May 27, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants